home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / you-075a.lha / you-075a / system_p.h < prev    next >
C/C++ Source or Header  |  1992-06-18  |  7KB  |  246 lines

  1. /* ******************************************************************** */
  2. /* system.h          Copyright (C) Codemist and University of Bath 1989 */
  3. /*                                                                      */
  4. /* Environment specific code                                           */
  5. /* ******************************************************************** */
  6.  
  7. /*
  8.  * $Id: system_p.h,v 1.6 1992/06/18 10:04:39 pab Exp $
  9.  *
  10.  * $Log: system_p.h,v $
  11.  * Revision 1.6  1992/06/18  10:04:39  pab
  12.  * more exports
  13.  *
  14.  * Revision 1.5  1992/06/11  23:58:39  pab
  15.  * fixed includes
  16.  *
  17.  * Revision 1.4  1992/05/28  16:10:42  rjb
  18.  * comment text after #endif
  19.  *
  20.  * Revision 1.3  1992/01/29  13:49:32  pab
  21.  * sysV fixes
  22.  *
  23.  * Revision 1.2  1991/09/11  12:07:47  pab
  24.  * 11/9/91 First Alpha release of modified system
  25.  *
  26.  * Revision 1.1  1991/08/12  16:50:06  pab
  27.  * Initial revision
  28.  *
  29.  * Revision 1.7  1991/05/16  11:31:20  pab
  30.  * 'C' garbage collector additions
  31.  *
  32.  * Revision 1.5  1991/02/28  13:53:19  kjp
  33.  * Fixed fopen/close macros in sysv - added GC state codes.
  34.  *
  35.  * Revision 1.4  1991/02/13  18:26:05  kjp
  36.  * Pass.
  37.  *
  38.  */
  39.  
  40. /*
  41.  * System specific prototypes...
  42.  *
  43.  * (see '.c' for details)
  44.  */
  45.  
  46. #ifndef SYSTEM_P_H
  47.  
  48. #define SYSTEM_P_H
  49.  
  50. /*
  51.  * Interfaces...
  52.  */
  53.  
  54. extern int system_running_processors;
  55. #define RUNNING_PROCESSORS() (system_running_processors)
  56.  
  57. /* ******************************************************************** */
  58. /*                             System V                                 */
  59. /* ******************************************************************** */
  60.  
  61. #ifdef MACHINE_SYSTEMV
  62.  
  63. extern int system_scheduler_number;
  64.  
  65. #define system_fopen(f,m) (fopen(f,m))
  66. #define system_fclose(f)  (fclose(f))
  67.  
  68. extern int system_read(int,char*,int);
  69.  
  70. extern char *system_malloc(int);
  71. extern char *system_static_malloc(int);
  72. /*
  73. #define system_allocate_semaphore(addr) (*(addr)=semget(IPC_PRIVATE,1,NULL))
  74. #define system_initialise_semaphore(addr) semctl(*(addr),0,SETVAL,1)
  75. #define system_open_semaphore(addr) semop(*(addr),&system_sem_handler,1)
  76. #define system_close_semaphore(addr) semctl(*(addr),0,SETVAL,1)
  77. */
  78.  
  79. extern void system_allocate_semaphore(SystemSemaphore *);
  80. extern void system_initialise_semaphore(SystemSemaphore *);
  81. extern void system_open_semaphore(LispObject *,SystemSemaphore *);
  82. extern void system_close_semaphore(SystemSemaphore *);
  83. extern int system_maybe_open_semaphore(LispObject *, SystemSemaphore *);
  84.  
  85. extern LispObject system_thread_rig(LispObject*,LispObject);
  86. extern LispObject system_thread_start(LispObject);
  87. extern LispObject system_thread_call(LispObject);
  88. extern LispObject system_thread_suspend(void);
  89. extern LispObject system_thread_reschedule(void);
  90. extern void system_thread_abort(void);
  91.  
  92. #define GC_sync_test() \
  93.           (SYSTEM_GLOBAL_VALUE(GC_state) == GC_SINKING \
  94.             ? ((void) garbage_collect(stacktop),TRUE) \
  95.         : FALSE)
  96.  
  97. #endif
  98.  
  99. /* ******************************************************************** */
  100. /*                            Any Machine                               */
  101. /* ******************************************************************** */
  102.  
  103. #ifdef MACHINE_ANY
  104.  
  105. #ifndef PROCESSORS
  106. #define PROCESSORS (1)
  107. #endif
  108.  
  109. #define system_fopen(f,m) (fopen(f,m))
  110. #define system_fclose(f)  (fclose(f))
  111.  
  112. #define system_read(a,b,c) (read(a,b,c))
  113.  
  114. extern char *system_malloc(int);
  115. #ifdef CGC
  116. #define  system_malloc(n) gc_malloc(n)
  117. #define system_static_malloc(n) gc_malloc(n)
  118. #else
  119. extern char *system_static_malloc(int);
  120. #endif
  121.  
  122. #define system_allocate_semaphore(addr) IGNORE(*addr)
  123. #define system_initialise_semaphore(addr)
  124. #define system_open_semaphore(x,addr)
  125. #define system_close_semaphore(addr)
  126. #define system_maybe_open_semaphore(x,addr) (1)
  127.  
  128. extern int system_scheduler_number;
  129.  
  130. /* Place where 'system_thread' calls would be */
  131.  
  132. #define GC_sync_test()
  133.  
  134. #endif
  135.  
  136. /* ******************************************************************** */
  137. /*                               BSD                                    */
  138. /* ******************************************************************** */
  139.  
  140. #ifdef MACHINE_BSD
  141.  
  142. extern int system_scheduler_number;
  143.  
  144. #define system_fopen(f,m) (fopen(f,m))
  145. #define system_fclose(f)  (fclose(f))
  146.  
  147. #define system_read(a,b,c) (read(a,b,c))
  148.  
  149. extern char *system_malloc(int);
  150. extern char *system_static_malloc(int);
  151.  
  152. #define system_allocate_semaphore(addr) (*(addr)=1)
  153. #define system_initialise_semaphore(addr) (*(addr)=1)
  154. #define system_open_semaphore(x,addr) \
  155.           { \
  156.         if (*(addr)!=1){ \
  157.           fprintf(stderr,"Unexpected value of semaphore"); \
  158.          \
  159.         } \
  160.         *(addr) = 0; \
  161.       }
  162. #define system_close_semaphore(addr) (*(addr)=1)
  163. #define system_maybe_open_semaphore(x,addr) (*(addr) == 1 ? *addr = 0,1 : 0)
  164.  
  165. extern LispObject system_thread_rig(LispObject*,LispObject);
  166. extern LispObject system_thread_start(LispObject);
  167. extern LispObject system_thread_call(LispObject);
  168. extern LispObject system_thread_suspend(void);
  169. extern LispObject system_thread_reschedule(void);
  170. extern void system_thread_abort(void);
  171.  
  172. #define GC_sync_test()
  173.  
  174. #endif
  175.  
  176. #ifndef MACHINE_ANY
  177. extern void system_kick_sleepers(void);
  178. extern void system_sleep_until_kicked(void);
  179. #endif
  180. /* Thread system prototypes... */
  181.  
  182. extern SYSTEM_GLOBAL_ARRAY1(LispObject,system_scheduler_threads,MAX_PROCESSORS);
  183.  
  184. /* Initialisation prototypes... */
  185.  
  186. extern void runtime_initialise_system(void);
  187. extern void system_initialise_scheduler(void);
  188. extern void system_lisp_exit(int);
  189. extern int system_stacks_ok_p(LispObject *,LispObject);
  190.  
  191. #define THREAD_LIMBO (0)
  192. #define THREAD_READY (1)
  193. #define THREAD_RUNNING (2)
  194. #define THREAD_RETURNED (3)
  195. #define THREAD_ABORTED (4)
  196.  
  197. #define GC_SINKING    (0)
  198. #define GC_REGISTERED (1)
  199. #define GC_MARKED     (2)
  200. #define GC_DONE       (3)
  201.  
  202. extern SYSTEM_GLOBAL(int,GC_state);
  203.  
  204. #ifndef SYSTEM_MAX_SHARED_SIZE
  205. #define SYSTEM_MAX_SHARED_SIZE (4*1024*1024)
  206. #endif
  207.  
  208. #ifdef WITH_PROFILING
  209.  
  210. #include <sys/time.h>
  211.  
  212. #define PROFILE_RUNNING  ('R')
  213. #define PROFILE_IDLE     ('I')
  214. #define PROFILE_GC_START ('G')
  215. #define PROFILE_GC_END   ('E')
  216. #define PROFILE_BLOCKED  ('B')
  217.  
  218. #define PROFILE(x) x
  219.  
  220. #define DEF_PROFILE_TIMER(name) struct itimerval *name
  221.  
  222. #define INIT_PROFILE_TIMER(name) \
  223.           name \
  224.             = (struct itimerval *) \
  225.                 system_static_malloc(sizeof(struct itimerval)); \
  226.           name->it_interval.tv_sec = 0; \
  227.           name->it_interval.tv_usec = 10; \
  228.           name->it_value.tv_sec = 0; \
  229.           name->it_value.tv_usec = 0; \
  230.           setitimer(ITIMER_REAL,name,NULL); 
  231.  
  232. #define PROFILE_TIME(name) (name->it_value.tv_sec)
  233.  
  234. extern struct itimerval *system_local_timer;
  235.  
  236. #else
  237. #define PROFILE(x)
  238. #define DEF_PROFILE_TIMER(x)
  239. #define INIT_PROFILE_TIMER(x)
  240. #define PROFILE_TIME(x)
  241. #endif
  242.  
  243. #endif /* SYSTEM_P_H */
  244.  
  245.  
  246.